<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>修改密码 | {$site_name}</title>
<include file="user:include"/>
</head>
<body>

<div class="layui-card-body">
    <form action="/index/user/changePwd" class="layui-form layui-form-fixed">
        <input type="text" name="nickname" value="{$user.nickname}" hidden="">
        <div class="layui-form-item">
            <label class="layui-form-label">原密码</label>
            <div class="layui-input-block">
                <empty name="$user['pwd']">
                    <input type="text" id="oldpwd" name="oldpwd" class="layui-input layui-disabled" placeholder="您的原密码为空(可不填)" disabled>
                    <else/>
                    <input type="text" id="oldpwd" name="oldpwd" class="layui-input" placeholder="请输入原密码">
                </empty>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">新密码</label>
            <div class="layui-input-block">
                <input type="password" id="pwd" name="pwd" class="layui-input" >
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">确认密码</label>
            <div class="layui-input-block">
                <input type="password" id="repwd" name="repwd" class="layui-input" >
            </div>
        </div>

        <div class="layui-form-item" style="margin-top: 22px;text-align: center;">
            <button type="button" class="layui-btn layui-btn-primary" sa-event="closeDialog" >关闭</button>
            <button type="submit" class="layui-btn layui-btn-normal" lay-submit="" lay-filter="submit">立即提交</button>
        </div>
    </form>
</div>
<script>
    layui.use(['jquery','form'],function(){
        var $ = layui.jquery;
        var form = layui.form;

        //监听提交
        form.on('submit(submit)', function(data){

            if($("#pwd").val().length < 6){
                layer.tips('请至少输入6个字符作为密码',"#pwd",{'tips':3});
                return false;
            }

            if ($("#pwd").val() !== $("#repwd").val()) {
                layer.tips('两次输入的密码不一样！',"#repwd",{'tips':3});
                return false;
            }

            $.ajax({
                url: $(this).attr('action'),
                type: 'POST',
                dataType: 'json',
                timeout: 6000,
                data: data.field,
                success: function(res){

                    if (res.code === 200) {
                        top.layer.msg(res.msg);
                        parent.location.reload();
                    }
                    else {
                        top.layer.msg(res.msg,{icon:2});
                    }

                }
            });

            return false;
        });

    })
</script>

</body>
</html>